
class SimpleTime
  
  def initialize(hour=0, minute=0)
    @hour = hour.to_i+(minute.to_i/60)
    @minute = minute.to_i%60
  end
  
  def hour
    return @hour.to_i
  end
  
  def hour=(hour)
      @hour = hour
  end
  
  def minute
    return @minute.to_i
  end
  
  def minute=(minute)
     @minute = minute
  end

  def before?(simple_time)
    return (hour < simple_time.hour || (hour === simple_time.hour.to_i && minute < simple_time.minute))
  end
  def equal?(simple_time)
    return hour === simple_time.hour && minute === simple_time.minute
  end
  def after?(simple_time)
    return !(before?(simple_time) || equal?(simple_time))
  end
  # =>  Add the given time to this time
  def add(simple_time)
    @minute += (simple_time.minute)
    @hour += ((minute / 60) + simple_time.hour)
    @minute %= 60
  end

  # adds the given time a 24hours system
  #   # @effect add(simple_time)
  # =>  hour %= 24
  def add_as_time(simple_time)
    add(simple_time)
    @hour %= 24
  end
  # returns the difference between 2 times in a 24hours system
  def duration_to(simple_time)
    minutes = simple_time.minute - minute
    hours = simple_time.hour - hour
    if(minutes < 0)
      minutes += 60
      hours -= 1
    end
    if(hours < 0)
      hours+=24
    end
    return SimpleTime.new(hours, minutes)
  end

  def to_s
    return (@hour.to_s.length === 1?"0":"") + @hour.to_s + ":" + (@minute.to_s.length === 1?"0":"") + @minute.to_s
  end
  
end
